package com.mustafaiev.tair.cts.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.mustafaiev.tair.constant.PayerRole;
import com.mustafaiev.tair.cts.enums.EntityState;

/**
 * @author tair
 * 
 */
public class PayerDTO implements Serializable, Comparable<PayerDTO>,
		UserDetails {

	private static final long serialVersionUID = 4162713113037941975L;

	private Long id;

	private Long unitedKey;

	private Long group;

	private List<BasketDTO> baskets;

	private List<PurchaseDTO> purchases;

	private String firstname;

	private String lastname;

	private String email;

	private String password;

	private PayerRole role;

	private EntityState state;

	public PayerDTO() {

	}

	public Long getId() {
		return this.id;
	}

	public void setId(final Long id) {
		this.id = id;
	}

	public Long getUnitedKey() {
		return this.unitedKey;
	}

	public void setUnitedKey(final Long unitedKey) {
		this.unitedKey = unitedKey;
	}

	public Long getGroup() {
		return this.group;
	}

	public void setGroup(final Long group) {
		this.group = group;
	}

	public List<BasketDTO> getBaskets() {
		return this.baskets;
	}

	public void setBaskets(final List<BasketDTO> baskets) {
		this.baskets = baskets;
	}

	public List<PurchaseDTO> getPurchases() {
		return this.purchases;
	}

	public void setPurchases(final List<PurchaseDTO> purchases) {
		this.purchases = purchases;
	}

	public String getFirstname() {
		return this.firstname;
	}

	public void setFirstname(final String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return this.lastname;
	}

	public void setLastname(final String lastname) {
		this.lastname = lastname;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(final String email) {
		this.email = email;
	}

	@Override
	public String getPassword() {
		return this.password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}

	public PayerRole getRole() {
		return this.role;
	}

	public void setRole(final PayerRole role) {
		this.role = role;
	}

	@Override
	public int compareTo(final PayerDTO o) {

		if ((this.firstname != null) && (this.lastname != null)) {
			if (this.firstname.equals(o.getFirstname())
					&& this.lastname.equals(o.getLastname())) {
				return 0;
			}
			if ((this.firstname.compareTo(o.getFirstname()) >= 1)
					|| (this.lastname.compareTo(o.getLastname()) >= 1)) {
				return 1;
			}
			if ((this.firstname.compareTo(o.getFirstname()) < 0)
					|| (this.lastname.compareTo(o.getLastname()) < 0)) {
				return -1;
			}
		}
		return 0;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		final List<PayerRole> roles = new ArrayList<PayerRole>();
		roles.add(this.role);
		return roles;
	}

	@Override
	public String getUsername() {
		return this.email;
	}

	@Override
	public boolean isAccountNonExpired() {
		return false;
	}

	@Override
	public boolean isAccountNonLocked() {
		return false;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return false;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public EntityState getState() {
		return this.state;
	}

	public void setState(final EntityState state) {
		this.state = state;
	}

}
